/** by daoyu 2011-10-4*/

/** show the dialog of artist's assets, play them, and add to basket. */
function artist_assets(uid){
	$.get("/user/assets/" + uid + "/", function(data){
		$('#dialog').html(data);
		$('#dialog').dialog("destroy");
		$('#dialog').dialog( {
			title : 'Artist Assets',
			width : 800,
			draggable : false,
			resizable : false,
			modal : true,
			buttons : {
				Close : function() {
					$(this).dialog("close");
					$("#dialog").html("");
				}
			}
		});
	});
}

function play_asset(type, url){
	if (type==0){
		var player = flowplayer("asset_player", "/site_media/flowplayer-3.2.2.swf", {
			clip: {
				url: '/' + url,
				provider: 'h264streaming',
				autoPlay:true,
				autoBuffering:true,
				scaling: "scale"
			},
			plugins: {
				h264streaming: {
					url: '/site_media/flowplayer.pseudostreaming-3.2.2.swf'
				},
				controls: {
					url: '/site_media/flowplayer.controls-3.2.1.swf',
					play:true,
					stop:true,
					scrubber: true
				}
			}
		});	
	} else if (type == 1){
		$("#asset_player").html("<img src='/" + url + "' width='400px'>");
	} else if (type == 2){
		$("#asset_player").html("<a href='/" + url + "'> <img src='/site_media/img/attach_document.png'> <br/> Download it </a>");
	}
}

/** show the effect of this asset has been selected.*/
function select_effect(input){
	if ($(input).attr("checked")){
		$(input).parent().css("background", "gray");
	} else {
		$(input).parent().css("background", "");
	}
}

function add_to_basket(){
	$.post("/user/basket/add_assets/", $("form[id=add_asset_to_basket]").serialize(), function(){
		alert("Successfully add assets to basket.");
		window.location.href = window.location.href;
	});
}